/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __BLP_FILE_H__
#define __BLP_FILE_H__

#include "MPQArchive.h"

namespace PQGameCore
{
	/*
	http://en.wikipedia.org/wiki/.BLP
	*/
	class BLPHeader{
	public:
		char id[4];
		int type;
		
		char encoding;
		char alphaDepth;
		char alphaEncoding;
		char hasMips;

		int width;
		int height;
		int offsets[16];
		int sizes[16];

		int palette[256];

	};

	class BLPFile
	{
	private:
		MPQFile *_file;
		BLPHeader* _header;
		unsigned char* _buf;//file content buf ptr
		unsigned char* _mipmap[16];//maximum 16 level
		int _mipsCount;
		bool _compressed;
		bool _ok;
		void init();
	public:
		~BLPFile(void);
		BLPFile(MPQFile* mpqFile);
		inline bool ok()
		{
			return _ok;
		}
		
		void genUnCompressTex();
		void genCompressTex();

		inline bool isCompressed()
		{
			return _compressed;
		}
		
		unsigned char* getMipmap(int index)
		{
			if(index<0||index>=16){
				return 0;
			}
			return _mipmap[index];
		}

		inline int getMipsCount()
		{
			return _mipsCount;
		}

		inline int getWidth()
		{
			return _header->width;
		}

		inline int getHeight()
		{
			return _header->height;
		}

		//mipmap index
		inline int getMipmapSize(int index)
		{
			return _header->sizes[index];
		}

	};
}
#endif
